package dht.storage;

import dht.entity.GlobalVariables;

public class PathUtils {

	public static int getVnodeId(String fileName) {
		return Math.abs(fileName.hashCode()) % GlobalVariables.ringLength;
	}

	public static String getMetaName(String fileName) {
		return fileName + ".meta";
	}

	public static String getBlockName(String fileName, int blockId) {
		return fileName + "_" + blockId + ".blk";
	}

	public static String getBlockMetaName(String fileName, int blockId) {
		return fileName + "_" + blockId + ".blk.meta";
	}

	public static String getBlockPath(String blockName) {
		int vnodeId = getVnodeId(blockName);
		return getVnodePath(vnodeId) + "/" + blockName;
	}

	public static String getVnodePath(int vnodeId) {
		return GlobalVariables.dataPath + "/" + vnodeId;
	}

}
